<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="/Public/css/bootstrap.min.css">
  <link rel="stylesheet" href="/Public/css/flat-ui.min.css">
  <link rel="stylesheet" href="/Public/css/wangEditor.min.css">
  <link rel="stylesheet" href="/Public/css/admin.css" charset="utf-8">
  <title>随遇而安blog</title>
</head>
<body>
  <div class="navbar navbar-default  header" role="navigation">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
          <span class="sr-only">Toggle navigation</span>
        </button>
        <a class="navbar-brand" href="<?php echo U('Home/Index/index');?>" target="_blank">随遇而安Blog</a>
      </div>
      <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav">
          <li><a href="">首页</a></li>
          <li><a href="<?php echo U('Article/index');?>">文章管理</a></li>
          <li><a href="<?php echo U('Article/category');?>">分类管理</a></li>
          <li><a href="<?php echo U('Works/index');?>">作品管理</a></li>
        </ul>
      </div><!--/.nav-collapse -->
    </div>
</div>

    <div class="container content">
      <div class="panel panel-default">
      <!-- Default panel contents -->
      <div class="panel-heading">文章分类 <a href="javascript:;"   data-toggle="modal" data-target=".bs-example-modal-lg">添加分类</a></div>

      <!-- Table -->
      <table class="table">
        <thead>
          <tr>
            <th>id</th>
            <th>分类名称</th>
            <th>级别</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          <?php if(is_array($cates)): foreach($cates as $key=>$v): ?><tr>
              <th scope="row"><?php echo ($v["id"]); ?></th>
              <td><?php echo ($v["name"]); ?></td>
              <td><?php echo ($v["lv"]); ?></td>
              <td>
                <a class="btn btn-success btn-xs update" cid="<?php echo ($v["id"]); ?>" data-toggle="modal" data-target=".bs-update-modal-lg">修改</a>
                <a href="<?php echo U('Article/delCate',array('id'=>$v['id']));?>" class="btn btn-danger btn-xs">删除</a>
              </td>
            </tr><?php endforeach; endif; ?>
        </tbody>
      </table>
    </div>
    </div>
    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
      <div class="modal-dialog modal-lg">
        <form action="<?php echo U('Article/addCate');?>" method="post">
        <div class="modal-content">
          <h6>添加分类</h6>
          <div class="form-group">
                <label>级别</label>
                <input name="lv" type="number" class="form-control"  >
                <label>分类名称 </label>
                <input name="name" type="text" class="form-control" >
          </div>
            <button type="submit" class="btn btn-primary btn-lg btn-block">添加</button>
        </div>
        </form>
      </div>
    </div>
    <div class="modal fade bs-update-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
      <div class="modal-dialog modal-lg">
        <form action="<?php echo U('Article/updateCate');?>" method="post">
        <div class="modal-content">
          <h6>添加分类</h6>
          <div class="form-group">
              <input type="hidden" name="id">
                <label>级别</label>
                <input name="lv" type="number" class="form-control"  >
                <label>分类名称 </label>
                <input name="name" type="text" class="form-control" >
          </div>
            <button type="submit" class="btn btn-primary btn-lg btn-block">修改</button>
        </div>
        </form>
      </div>
    </div>
<footer class="container-full">

</footer>
<script src="/Public/js/vendor/jquery.min.js" charset="utf-8"></script>
<script src="/Public/js/flat-ui.min.js" charset="utf-8"></script>
<script src="/Public/js/app.js" charset="utf-8"></script>

<script>
$('.update').click(function(){
  $('.bs-update-modal-lg input[name=id]').val($(this).attr('cid'));
})
</script>
</body>
</html>